

*********************************
* This do-file runs regressions
*********************************

cap log close
log using "...", replace

*************************
******** Paths **********
*************************

global dir "..."

*************************
*** Defining Programs ***
*************************


capture program drop store_regular4
program define store_regular4, rclass

	args var

	local b = string(_b[`var'], "%10.4fc") 
	local se = "(" + string(_se[`var'], "%10.4fc") + ")"
	local p = 2*ttail(e(df_r),abs(_b[`var']/_se[`var']))
	*local p = 2*(1-normal(abs(_b[`var']/_se[`var'])))
	local star=""
		if `p' >.05 & `p' <=.10 { 	
			local star = "^{*}"
		}
		if `p' >.01 & `p' <=.05 { 	
			local star = "^{**}"
		}
		if `p' <=.01 {	
			local star = "^{***}" 
		}
	
	return local beta = "`b'"
	return local se = "`se'"
	return local star = "`star'"

end

capture program drop store_regular4_xt
program define store_regular4_xt, rclass

	args var

	local b = string(_b[`var'], "%10.4fc") 
	local se = "(" + string(_se[`var'], "%10.4fc") + ")"
	local p = 2*ttail(e(df_m),abs(_b[`var']/_se[`var']))
	*local p = 2*(1-normal(abs(_b[`var']/_se[`var'])))
	local star=""
		if `p' >.05 & `p' <=.10 { 	
			local star = "^{*}"
		}
		if `p' >.01 & `p' <=.05 { 	
			local star = "^{**}"
		}
		if `p' <=.01 {	
			local star = "^{***}" 
		}
	
	return local beta = "`b'"
	return local se = "`se'"
	return local star = "`star'"
	return local r2a = "`r2_a'"

end


capture program drop store_regular2
program define store_regular2, rclass

	args var

	local b = string(_b[`var'], "%10.2fc") 
	local se = "(" + string(_se[`var'], "%10.2fc") + ")"
	local p = 2*ttail(e(df_r),abs(_b[`var']/_se[`var']))
	*local p = 2*(1-normal(abs(_b[`var']/_se[`var'])))
	local star=""
		if `p' >.05 & `p' <=.10 { 	
			local star = "^{*}"
		}
		if `p' >.01 & `p' <=.05 { 	
			local star = "^{**}"
		}
		if `p' <=.01 {	
			local star = "^{***}" 
		}
	
	return local beta = "`b'"
	return local se = "`se'"
	return local star = "`star'"

end



*****************************************************************
**************** T1: Summary Stats ******************************
*****************************************************************

use "$dir/data/working_data.dta", replace
keep if tag_ind==1

capture erase "$dir/Table/sum_stats.tex"
capture file close fh

file open fh using "$dir/Tables/sum_stats.tex", write replace

file write fh ///
	"\begin{tabular}{l cccccccc}" _n ///
	"\toprule" _n ///
"Variable &  Mean &&  SD && Median && N \\" _newline ///
"\hline \emph{Panel A: Demographic and School-level variables} \\" _newline

foreach var in public_school ///
	private_non_profit first_enrollment_selective_v2 ///
	age median_hhld_income bach_g_by35 gradschool_g_by35  ///
	balance_year4  baseline_score four_yr_score six_yr_score score_2018 score_mean score_volatility ///
	four_yr_delinquency six_yr_delinquency delinquency_2018 four_yr_default six_yr_default default_2018 ///
	four_yr_percent_c percent_2017_c max_pct_default ///
	    {  

	qui su `var', d
	local mean_1 = string(r(mean), "%10.4fc") 
	local sd_1 = string(r(sd), "%10.4fc") 
	local median_1 = string(r(p50), "%10.4fc") 
	local min_1 = string(r(min), "%10.0fc") 
	local max_1 = string(r(max), "%10.0fc") 
	
	cap drop number_obs
	egen number_obs = count(`var')
	local n_1 = string(number_obs[1], "%10.0fc") 

	local label : variable label `var' 
	file write fh "\hspace{5 pt} `label'  & `mean_1' && `sd_1' && `median_1' && `n_1' \\ " _newline
	}

* Panel B: tuition increases
use "$dir/data/working_data.dta", replace
g gcid=cid
* for each individual compute max shock
sort gcid
cap drop max_deltatuition
bysort gcid: egen max_deltatuition = max(deltatuition) if academicyear>=entry_year+1
sort gcid max_deltatuition
bysort gcid: replace max_deltatuition=max_deltatuition[1]

sort gcid
cap drop max_shock
bysort gcid: egen max_shock = max(perc_tuit) if academicyear>=entry_year+1
sort gcid max_shock
bysort gcid: replace max_shock=max_shock[1]

keep if academicyear>=entry_year+1

label var deltatuition "Yearly tuition change"
label var perc_tuit "Percent yearly tuition change"
label var max_deltatuition "Max tuition change by student"
label var max_shock "Max percent tuition change by student"
label var tuition_bill "Total tuition years 1-4 after entry (10,000)"

	file write fh "\\ \emph{Panel B: Tuition variables} \\" _newline


* shock size conditional on $1000 shock
g deltatuition_1000 = deltatuition if dummy_change_1000==1
label var deltatuition_1000 "Yearly tuition change conditional on 1000 shock"
g perc_tuit_1000 = perc_tuit if dummy_change_1000==1
label var perc_tuit_1000 "Percent yearly tuition change conditional on 1000 shock"
foreach var in  deltatuition perc_tuit deltatuition_1000 perc_tuit_1000 { 

	qui su `var' if academicyear>=entry_year+1 & academicyear<=entry_year+4, d
	local mean_1 = string(r(mean), "%10.4fc") 
	local sd_1 = string(r(sd), "%10.4fc") 
	local median_1 = string(r(p50), "%10.4fc") 
	local min_1 = string(r(min), "%10.0fc") 
	local max_1 = string(r(max), "%10.0fc") 
	
	cap drop number_obs
	egen number_obs = count(`var')
	local n_1 = string(number_obs[1], "%10.0fc") 

	local label : variable label `var' 
	file write fh "\hspace{5 pt} `label'  & `mean_1' && `sd_1' && `median_1' && `n_1' \\ " _newline
	}
	
* mark those with a shock:
foreach x in 800 900 1000 1100 1200 2000 {
	cap drop aux_dummy_`x'
	bys cid: egen aux_dummy_`x'=max(dummy_change_`x')
	}

	
cap drop tag_id
egen tag_id = tag(cid)
keep if tag_id==1

foreach var in tuition_bill max_shock max_deltatuition  { 

	qui su `var', d
	local mean_1 = string(r(mean), "%10.4fc") 
	local sd_1 = string(r(sd), "%10.4fc") 
	local median_1 = string(r(p50), "%10.4fc") 
	local min_1 = string(r(min), "%10.0fc") 
	local max_1 = string(r(max), "%10.0fc") 
	
	cap drop number_obs
	egen number_obs = count(`var')
	local n_1 = string(number_obs[1], "%10.0fc") 

	local label : variable label `var' 
	file write fh "\hspace{5 pt} `label'  & `mean_1' && `sd_1' && `median_1' && `n_1' \\ " _newline
	}
	
	
	
foreach x in 800 900 1000 1100 1200 2000 {
	label var aux_dummy_`x' "Fraction `x' or higher"
	qui su aux_dummy_`x', d
	
	local mean_1 = string(r(mean), "%10.4fc") 
	local sd_1 = string(r(sd), "%10.4fc") 
	local median_1 = string(r(p50), "%10.4fc") 
	local min_1 = string(r(min), "%10.0fc") 
	local max_1 = string(r(max), "%10.0fc") 
	

	cap drop number_obs
	egen number_obs = count(cid)
	local n_1 = string(number_obs[1], "%10.0fc") 
	local label : variable label aux_dummy_`x'
	file write fh "\hspace{5 pt} `label'  & `mean_1' && `sd_1' && `median_1' && `n_1' \\ " _newline

	}


	
	
file write fh %-16s "\hline" _newline %-16s "\end{tabular}"
file close fh


* Separate stats for students in schools with and without tuition shock
use "$dir/data/working_data.dta", replace
cap drop aux_dummy_1000
bys cid: egen aux_dummy_1000=max(dummy_change_1000)
	
keep if tag_ind==1
label var tuition_bill "Total tuition years 1-4 after entry (10,000)"
capture erase "$dir/Tables/sum_stats_split.tex"
capture file close fh

file open fh using "$dir/Tables/sum_stats_split.tex", write replace

file write fh ///
	"\begin{tabular}{l ccccc}" _n ///
	"\toprule" _n ///
"Variable & All && Exposed to shock &&  Not exposed to shock \\" _newline ///
"\hline \\" _newline

foreach var in public_school ///
	private_non_profit first_enrollment_selective_v2 ///
	age median_hhld_income bach_g_by35 ///
	gradschool_g_by35  ///
	balance_year4  baseline_score four_yr_score six_yr_score score_2018 score_mean score_volatility ///
	four_yr_delinquency six_yr_delinquency delinquency_2018 four_yr_default six_yr_default default_2018 ///
	four_yr_percent_c percent_2017_c max_pct_default   { 

	qui su `var', d
	local mean_1 = string(r(mean), "%10.4fc") 
	local n_1 = string(r(N), "%10.0fc") 

	qui su `var' if aux_dummy_1000==1, d
	local mean_2 = string(r(mean), "%10.4fc") 
	local n_2 = string(r(N), "%10.0fc") 
	
	qui su `var' if aux_dummy_1000!=1, d
	local mean_3 = string(r(mean), "%10.4fc") 
	local n_3 = string(r(N), "%10.0fc") 
	
	local label : variable label `var' 
	file write fh "\hspace{5 pt} `label'  & `mean_1' && `mean_2' && `mean_3' \\ " _newline
	}
	qui su public_school, d
	local n_1 = string(r(N), "%10.0fc") 

	qui su public_school if aux_dummy_1000==1, d
	local n_2 = string(r(N), "%10.0fc") 
	
	qui su public_school if aux_dummy_1000!=1, d
	local n_3 = string(r(N), "%10.0fc") 
	
	file write fh "\hspace{5 pt} Observations  & `n_1' && `n_2' && `n_3' \\ " _newline


file write fh %-16s "\hline" _newline %-16s "\end{tabular}"
file close fh

**********************************************************

* Compute number of schools and fraction of all schools with a shock

use "$dir/data/working_data.dta", replace
foreach x in 800 900 1000 1100 1200 2000 10 20 {
	bys cid: egen aux_dummy_`x'=max(dummy_change_`x') // this var tells us whether school had a schock in time period
	}

egen tag_school = tag(college_code_branch)	
keep if tag_school==1

collapse (sum) total_aux_dummy_10 = aux_dummy_10 total_aux_dummy_20 = aux_dummy_20 ///
	total_aux_dummy_800 = aux_dummy_800  total_aux_dummy_900 = aux_dummy_900  ///
	total_aux_dummy_1000 = aux_dummy_1000 total_aux_dummy_1100 = aux_dummy_1100  ///
	total_aux_dummy_1200 = aux_dummy_1200  total_aux_dummy_2000 = aux_dummy_2000  ///
	(mean) aux_dummy_800 aux_dummy_900 aux_dummy_1000 aux_dummy_1100 aux_dummy_1200 aux_dummy_2000

	
capture erase "$dir/Tables/sum_stats_number_shocks.tex"
capture file close fh

file open fh using "$dir/Tables/sum_stats_number_shocks.tex", write replace

file write fh ///
	"\begin{tabular}{c ccc}" _n ///
	"\toprule" _n ///
"Shock Size & Number of schools && Fraction of total \\" _newline ///
"\hline \\" _newline
	
foreach var in 800 900 1000 1100 1200 2000 {
	
	local shock = string(`var', "%10.0fc") 
	
	qui su total_aux_dummy_`var', d
	local number = string(r(mean), "%10.0fc") 
	
	qui su aux_dummy_`var', d
	local fraction = string(r(mean), "%10.4fc") 
	
	file write fh "\hspace{5 pt} `shock'  & `number' && `fraction' \\ " _newline
	}
		
foreach var in 10 20 {
	
	local shock = string(`var', "%10.0fc") 
	
	qui su total_aux_dummy_`var', d
	local number = string(r(mean), "%10.0fc") 
	
	qui su aux_dummy_`var', d
	local fraction = string(r(mean), "%10.4fc") 
	
	file write fh "\hspace{5 pt} `shock' percent  & `number' && `fraction' \\ " _newline
	}
	
file write fh %-16s "\hline" _newline %-16s "\end{tabular}"
file close fh


* Number by year and control type

use "$dir/data/working_data.dta", replace

egen tag_school_year = tag(college_code_branch academicyear)	
keep if tag_school_year==1

cap drop yearchange
gen yearchange=academicyear if dummy_change_1000==1

collapse (sum) total_aux_dummy_1000 = dummy_change_1000, by(yearchange private_school private_non_profit)

bysort yearchange: egen total = total(total_aux_dummy_1000)
	
capture erase "$dir/Tables/sum_stats_year_and_control.tex"
capture file close fh

file open fh using "$dir/Tables/sum_stats_year_and_control.tex", write replace

file write fh ///
	"\begin{tabular}{c ccccccc}" _n ///
	"\toprule" _n ///
"Year & All && Public && Private for-profit && Private non-profit \\" _newline ///
"\hline \\" _newline
	
forvalues x = 2005(1)2014 {
	
	qui su total if yearchange==`x' & private_school==0, d
	local mean_0 = string(r(mean), "%10.0fc")
	
	qui su total_aux_dummy_1000 if yearchange==`x' & private_school==0, d
	local mean_1 = string(r(mean), "%10.0fc") 
	
	qui su total_aux_dummy_1000 if yearchange==`x' & private_non_profit==0 & private_school==1, d
	local mean_2 = string(r(mean), "%10.0fc") 
	
	qui su total_aux_dummy_1000 if  yearchange==`x' &  private_non_profit==1, d
	local mean_3 = string(r(mean), "%10.0fc") 
	
	file write fh "\hspace{5 pt} `x' & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _newline
	}
	
	collapse (sum) total total_aux_dummy_1000 ///
	(mean) mean_tot= total mean_aux = total_aux_dummy_1000 ///
	(p50) median_tot= total, by(private_school private_non_profit)

	qui su total if private_school==0, d
	local mean_0 = string(r(mean), "%10.0fc")
	
	qui su total_aux_dummy_1000 if private_school==0, d
	local mean_1 = string(r(mean), "%10.0fc") 
	
	qui su total_aux_dummy_1000 if private_non_profit==0 & private_school==1, d
	local mean_2 = string(r(mean), "%10.0fc") 
	
	qui su total_aux_dummy_1000 if  private_non_profit==1, d
	local mean_3 = string(r(mean), "%10.0fc") 
	file write fh "\\ " _newline
	file write fh "\hline \hspace{5 pt} Total & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _newline
	
	qui su mean_tot if private_school==0, d
	local mean_0 = string(r(mean), "%10.0fc")
	
	qui su mean_aux if private_school==0, d
	local mean_1 = string(r(mean), "%10.0fc") 
	
	qui su mean_aux if private_non_profit==0 & private_school==1, d
	local mean_2 = string(r(mean), "%10.0fc") 
	
	qui su mean_aux if  private_non_profit==1, d
	local mean_3 = string(r(mean), "%10.0fc") 
	
	file write fh "\hspace{5 pt} Yearly average & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _newline

file write fh %-16s "\bottomrule" _newline %-16s "\end{tabular}"
file close fh


****************************************************************
* Separate stats for students in public and private schools
use "$dir/data/working_data.dta", replace
	
keep if tag_ind==1
label var tuition_bill "Total tuition years 1-4 after entry (10,000)"
capture erase "$dir/Tables/sum_stats_school_type.tex"
capture file close fh

file open fh using "$dir/Tables/sum_stats_school_type.tex", write replace

file write fh ///
	"\begin{tabular}{l ccccc}" _n ///
	"\toprule" _n ///
"Variable & Public school &&  Private for profit && Private non-profit \\" _newline ///
"\hline \emph{Panel A: Demographic and School-level variables} \\" _newline

foreach var in first_enrollment_selective_v2 ///
	age median_hhld_income bach_g_by35 ///
	balance_year4  baseline_score four_yr_score six_yr_score score_2018 score_mean score_volatility ///
	four_yr_delinquency six_yr_delinquency delinquency_2018 four_yr_default six_yr_default default_2018 ///
	four_yr_percent_c percent_2017_c max_pct_default ///
	 { 

	qui su `var' if private_school==0, d
	local mean_1 = string(r(mean), "%10.4fc") 
	local n_1 = string(r(N), "%10.0fc") 

	qui su `var' if private_non_profit==0 & private_school==1, d
	local mean_2 = string(r(mean), "%10.4fc") 
	local n_2 = string(r(N), "%10.0fc") 
	
	qui su `var' if  private_non_profit==1, d
	local mean_3 = string(r(mean), "%10.4fc") 
	local n_3 = string(r(N), "%10.0fc") 
	
	local label : variable label `var' 
	file write fh "\hspace{5 pt} `label'  & `mean_1' && `mean_2' && `mean_3' \\ " _newline
		
	}
	
* Panel B: tuition increases
use "$dir/data/working_data.dta", replace
g gcid=cid
* for each individual compute max shock
sort gcid
cap drop max_deltatuition
bysort gcid: egen max_deltatuition = max(deltatuition) if academicyear>=entry_year+1
sort gcid max_deltatuition
bysort gcid: replace max_deltatuition=max_deltatuition[1]

sort gcid
cap drop max_shock
bysort gcid: egen max_shock = max(perc_tuit) if academicyear>=entry_year+1
sort gcid max_shock
bysort gcid: replace max_shock=max_shock[1]

keep if academicyear>=entry_year+1

label var deltatuition "Yearly tuition change"
label var perc_tuit "Percent yearly tuition change"
label var max_deltatuition "Max tuition change by student"
label var max_shock "Max percent tuition change by student"
label var tuition_bill "Total tuition years 1-4 after entry (10,000)"

	file write fh "\\ \emph{Panel B: Tuition variables} \\" _newline


* shock size conditional on $1000 shock
g deltatuition_1000 = deltatuition if dummy_change_1000==1
label var deltatuition_1000 "Yearly tuition change conditional on 1000 shock"
g perc_tuit_1000 = perc_tuit if dummy_change_1000==1
label var perc_tuit_1000 "Percent yearly tuition change conditional on 1000 shock"
foreach var in  deltatuition perc_tuit deltatuition_1000 perc_tuit_1000 { 

	qui su `var' if academicyear>=entry_year+1 & academicyear<=entry_year+4 & private_school==0, d
	local mean_1 = string(r(mean), "%10.4fc") 

	qui su `var' if academicyear>=entry_year+1 & academicyear<=entry_year+4 & private_non_profit==0 & private_school==1, d
	local mean_2 = string(r(mean), "%10.4fc") 
	
	qui su `var' if academicyear>=entry_year+1 & academicyear<=entry_year+4 & private_non_profit==1, d
	local mean_3 = string(r(mean), "%10.4fc") 

	
	local label : variable label `var' 
	file write fh "\hspace{5 pt} `label'  & `mean_1' && `mean_2' && `mean_3' \\ " _newline
	
	}
	
* mark those with a shock:
foreach x in 800 900 1000 1100 1200 2000 {
	cap drop aux_dummy_`x'
	bys cid: egen aux_dummy_`x'=max(dummy_change_`x')
	}

	
cap drop tag_id
egen tag_id = tag(cid)
keep if tag_id==1

foreach var in tuition_bill max_shock max_deltatuition  { 

	qui su `var' if private_school==0, d
	local mean_1 = string(r(mean), "%10.4fc") 

	qui su `var' if private_non_profit==0 & private_school==1, d
	local mean_2 = string(r(mean), "%10.4fc") 
	
	qui su `var' if private_non_profit==1, d
	local mean_3 = string(r(mean), "%10.4fc") 

	
	local label : variable label `var' 
	file write fh "\hspace{5 pt} `label'  & `mean_1' && `mean_2' && `mean_3' \\ " _newline
	
	}
	
	
	
foreach x in 800 900 1000 1100 1200 2000 {
	label var aux_dummy_`x' "Fraction `x' or higher"

	qui su aux_dummy_`x'  if private_school==0, d
	local mean_1 = string(r(mean), "%10.4fc") 

	qui su aux_dummy_`x' if private_non_profit==0 & private_school==1, d
	local mean_2 = string(r(mean), "%10.4fc") 
	
	qui su aux_dummy_`x' if private_non_profit==1, d
	local mean_3 = string(r(mean), "%10.4fc") 

	
	local label : variable label aux_dummy_`x' 
	file write fh "\hspace{5 pt} `label'  & `mean_1' && `mean_2' && `mean_3' \\ " _newline
	}
	


file write fh %-16s "\hline" _newline %-16s "\end{tabular}"
file close fh


*****************************************************************
************************** T2: OLS ******************************
*****************************************************************


* Table: OLS relation between tuition and outcomes
use "$dir/data/working_data.dta", replace
*use "C:\Users\fos\Dropbox\Debt and graduate studies\Ruchi\data\working_data.dta", replace

* one obs per student:
keep if tag_ind==1				/* 58,673 observations */

* Fixed effects:
egen school=group(college_code_branch)

* Main outcomes
label var gradschool_g_by35 "Graduate school"
label var balance_year4 "Debt"

label var bach_g_by35 "Bachelors"
label var graduated_first "Graduated first"
label var graduated_any "Graduated any"

label var total_student_debt_4 "Orig. 4 years"
label var grad_ever "Grad school"
label var masters_ever "Masters"
label var transfer "Transfers"
label var transfer_2yr "Transf. 2yr"
label var age "Age entry"
label var public_school "Public school"
label var private_school "Private school"

label var stem "STEM"
label var business "Business"
label var art "Art"
label var vocation "Vocations"
label var transfer_4yr  "Transf. 4yr"
label var tuition_bill "Tuition yrs 1-4"

label var four_yr_score "Score 4 years" 
label var six_yr_score "Score 6 years" 
label var score_2018 "Score 2018"
label var score_mean "Mean Score"
label var score_volatility "St Dev Score"

label var four_yr_delinquency "Delinq. 4 years" 
label var six_yr_delinquency "Delinq. 6 years" 
label var delinquency_2018 "Delinq. 2018" 

label var four_yr_default "Default 4 years" 
label var six_yr_default "Default 6 years" 
label var default_2018 "Default 2018" 

* label var four_yr_percent "Frac Debt Delinq. 4 years"
label var four_yr_percent_c "Frac Debt Delinq. 4 years"
label var six_yr_percent_c "Frac Debt Delinq. 6 years"
label var six_yr_percent_c "Frac Debt Delinq. 6 years"
label var percent_2017_c "Frac Debt Delinq. 2017"
/*
cap drop school_cohort
egen school_cohort=group(college_code_branch entry_year)
*/

* Tables: OLS
local fe "entry_year school"
local cluster_var "school"

local reg_vars_1 "balance_year4 gradschool_g_by35 bach_g_by35 transfer"	
local reg_vars_2 "four_yr_score six_yr_score score_2018 score_mean score_volatility"
local reg_vars_3 "four_yr_delinquency four_yr_default six_yr_delinquency six_yr_default"	
local reg_vars_4 "delinquency_2018 default_2018 percent_2017_c"	


local reg_vars_5 "sl_holder_by8years sl_holder_by6years sl_holder_by4years sl_holder_by30"
local reg_vars_6 "sl_bal_at8years sl_bal_at6years sl_bal_at4years sl_bal_at30"
local reg_vars_7 "sl_dq_by8years sl_dq_by6years sl_dq_by4years sl_dq_by30"

local reg_vars_8 "mort2_by8years mort2_by6years mort2_by4years mort2_by30"
local reg_vars_9 "mort2_bal_at8years mort2_bal_at6years mort2_bal_at4years mort2_bal_at30"
local reg_vars_10 "mort2_dq_by8years mort2_dq_by6years mort2_dq_by4years mort2_dq_by30"

local reg_vars_11 "credit_by8years credit_by6years credit_by4years credit_by30"
local reg_vars_12 "credit_card_bal_at8years credit_card_bal_at6years credit_card_bal_at4years credit_card_bal_at30"
local reg_vars_13 "credit_card_dq_by8years credit_card_dq_by6years credit_card_dq_by4years credit_card_dq_by30"

local reg_vars_14 "auto_by8years auto_by6years auto_by4years auto_by30"
local reg_vars_15 "auto_bal_at8years auto_bal_at6years auto_bal_at4years auto_bal_at30"
local reg_vars_16 "auto_dq_by8years auto_dq_by6years auto_dq_by4years auto_dq_by30"

local reg_vars_17 "mean_agi_at30 diff_agi_30_initial"
	

* Run up to x where `x' is max number of reg_vars_`x':
forvalues tablenum = 1/17 {
	local n_vars : word count `reg_vars_`tablenum'' 
	di `n_vars'
	local c_columns = `n_vars'-1
	local table_declaration "l c"
	local table_clines ""
	local number_header " & "
	local var_header " & "

	local x=0
	
	local b = "\emph{Tuition yrs. 1-4} "
	local se = " "
	local obs = " Observations "
	local r2 = " R-squared "
	local clusters = " Clusters "
	local mean = " Mean "
	
	foreach var in `reg_vars_`tablenum''  {

		qui reghdfe `var' tuition_bill, a(`fe') cl(`cluster_var')
		* construct tables:
		local label : variable label `var' 

		* reg coefs:
		store_regular4 tuition
	
		local y = `x'+1

		if `x'>0 {
			if `x'<`n_vars' {
				local table_declaration = "`table_declaration'"+"cc"
			}
			local number_header = "`number_header'" + " && " + "\multicolumn{1}{c}{(`y')}"
			local var_header = "`var_header'" + " && " + "\multicolumn{1}{c}{\emph{`label'}}"
			local b = "`b'" + " && " + "$`r(beta)'`r(star)'$"
			local se = "`se'" + " && " + "`r(se)'"
			local obs = "`obs'" + " && " + string(e(N), "%10.0fc")
			local r2 = "`r2'" + " && " + string(e(r2), "%10.2fc")
			local clusters = "`clusters'" + " && " + string(e(N_clust), "%10.0fc")
			qui su `var', d
			local mean = "`mean'" + " && " + string(r(mean), "%12.4fc")
	
		}
		if `x'==0 {
			local number_header = "`number_header'"  + " \multicolumn{1}{c}{(`y')}"
			local var_header = "`var_header'" + " \multicolumn{1}{c}{\emph{`label'}}"
			local b = "`b'" + "& " + "$`r(beta)'`r(star)'$"
			local se = "`se'" + "& " + "`r(se)'"
			local obs = "`obs'" + "& " + string(e(N), "%10.0fc")
			local r2 = "`r2'" + "& " + string(e(r2), "%10.2fc")
			local clusters = "`clusters'" + "& " + string(e(N_clust), "%10.0fc")
			qui su `var', d
			local mean = "`mean'" + "& " + string(r(mean), "%12.4fc")
		}

		local aux = 2*`y'
		local table_clines = "`table_clines'" + " \cline{`aux'-`aux'}"
		local x=`x'+1
	}
		local table_full_line = "\cline{2-`aux'} "

	cap file close fh
		capture erase "$dir/Tables/OLS_regs_`tablenum'_fullFE.tex"
		file open fh using "$dir/Tables/OLS_regs_`tablenum'_fullFE.tex", write replace

		file write fh ///
			"\begin{tabular}{`table_declaration'}" _n ///
			"\toprule" _n 
			
		file write fh "`number_header' \\" _n ///
			"`table_clines' " _n ///
			"`var_header' \\" _n ///	
			"`table_full_line' " _n
			
		file write fh ///
			"`b' \\ "  _n ///
			"`se'  \\ \\"  _n ///
			"`obs'  \\ " _n ///
			"`r2' \\ " _n  ///
			"`clusters'  \\ " _n ///
			"`mean'  \\ " _n
			
			
		file write fh ///
			"\bottomrule" _n ///
			"\end{tabular}"  _n _n _n _n _n

	file close fh

} // tablenum


* OLS results by income quartile
	
cap drop aux
xtile aux = median_hhld_income, nq(4)
foreach var in `reg_vars_1' {
	g coef_income = .
	g std_err_income = .
	g var_income = .
	
	forvalues y=1/4 {
	qui reghdfe `var' tuition_bill if aux==`y', a(`fe') cl(`cluster_var')
	store_regular4 tuition
	* Figure (within variable loop):
	local position = `y'
	replace var_income=`y' in `position'
	replace coef_income=`r(beta)' in `position'
	replace std_err_income=`r(se)' in `position'
	}

	
	* Figure title:
	local label_`x' : variable label `var' 
	
	* graph:
	cap drop LB
	cap drop UB
	g LB = coef_income-1.96*std_err_income
	g UB = coef_income+1.96*std_err_income
	
	twoway (bar coef_income var_income, color(black) sort barwidth(0.8)) (rcap UB LB var_income, lc(black)), ///
		ylabel(,format(%12.4fc) labs(small)) ///
		xlabel(1(1)4, labs(small)) ///
		ytitle("Reg coefficient for `label_`x''", size(small))  ///
		xtitle("Income quartile", size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/inc_quartile_`var'_FULLFE.pdf", replace as(pdf)
	drop coef_income std_err_income var_income
	
}

*****************************************************************
***************** T3: Reduced form and IV ***********************
*****************************************************************

* START IV REGRESSION HERE
foreach size_of_shock in  1000 { // 0  20 800 900 1000  1100 1200 2000 {
* local size_of_shock = 1000 // 5, 10, 20, etc., 0 for all shocks

use "$dir/data/working_data.dta", replace


* replace tuition_bill=log(tuition_bill)
keep if tuition_bill<.

cap drop yearchange
gen yearchange=academicyear if dummy_change_`size_of_shock'==1
keep if yearchange>=2005 // data from 2000 on tuition only

* FOR NOW: 
* keep if entry_year>=2004
* keep if yearchange>=2002

* Calculate student's grade in year of tuition shock (e.g., freshman in 2019: 2019 - 2019 + 1 = 1)
cap drop grade_when_change
g grade_when_change = (academicyear-entry_year+1) if yearchange==academicyear // 1 is Freshman

* Sample selection due to data coverage: grades when year change occurs
preserve
keep if grade_when_change>=2 & grade_when_change<=4
format yearchange %ty
graph bar (count) academicyear, over(grade, label(labsize(small))) over(yearchange, label(labsize(small))) asyvars percentage stack graphregion(color(white)) bgcolor(white) ///
		ylabel(, format(%12.0fc) labs(small)) ///
		bargap(10) intensity(70) ///
		ytitle("Percent of students in each grade", size(small))  ///
		title("Grade distribution by year of shock", size(small)) ///
		legend(lab(1 "Year 2") lab(2 "Year 3") lab(3 "Year 4") size(small))
		graph export "$dir/Figures/grades_by_year_`size_of_shock'.pdf", replace as(pdf)

restore


foreach var in grade_when_change yearchange {
	sort cid `var'
	bysort cid: replace `var'=`var'[1]
	}

replace yearchange=0 if yearchange==. // control group	


* one obs per student:
cap drop tag_ind
egen tag_ind = tag(cid)
keep if tag_ind==1

* Distribution of grades
preserve
	keep if tag_ind==1
	keep if grade_when_change>=2 & grade_when_change<=4
	collapse (count) number = perc_tuit, by(grade)
	drop if grade>4
	twoway (bar number grade, fcolor(black) lwidth(medium) lcolor(white)), ylabel(0(400)2600, format(%12.0fc) labs(small)) ///
		xlabel(2(1)4, labs(small)) ///
		ytitle("Students", size(small))  ///
		xtitle(Year after entry, size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/grades_`size_of_shock'.pdf", replace as(pdf)

restore



******* Selection: *******
* Treatment group is only grades 2 and above.
* Control is not exposed
* keep if (grade_when>=2)
replace college_code_branch=college_code_branch+"EARLY" if grade_when<2 | (grade_when>5 & grade_when<.) // This means the comparison group is cohort 5 for treated

* dummies grades 2 to 4:
forvalues x=2/4 {
	cap drop grade_change_`x' 
	g grade_change_`x' = grade_when_change==`x'
	label var grade_change_`x' "Grade in tuition shock"
	}


* for linear specification:
g grade_change_linear = grade_when_change if grade_when_change>=2 & grade_when_change<=4
replace grade_change_linear=0 if grade_change_linear==.


/*
forvalues x=2/4 {
	cap drop tuitition_grade_`x'
	g tuitition_grade_`x' = deltatuition*grade_change_`x'
	// include full sample, helps to estimate FE
	replace tuitition_grade_`x'=0 if tuitition_grade_`x'==.
	}	
	replace deltatuition=0 if deltatuition==.
*/
* Main outcomes
label var gradschool_g_by35 "Graduate school"
label var balance_year4 "Debt"

label var bach_g_by35 "Bachelors"

label var total_enrollment_time "Months enrolled"
label var graduated_first "Graduated first"
label var graduated_any "Graduated any"
label var balance_year4 "Debt"
label var total_student_debt_4 "Orig. 4 years"
label var grad_ever "Grad school"
label var masters_ever "Masters"
label var transfer "Transfers"
label var transfer_2yr "Transf. 2yr"
label var age "Age entry"
label var public_school "Public school"
label var private_school "Private school"

label var stem "STEM"
label var business "Business"
label var art "Art"
label var vocation "Vocations"
label var transfer_4yr  "Transf. 4yr"
label var tuition_bill "Tuition yrs 1-4"

label var four_yr_score "Score 4 years" 
label var six_yr_score "Score 6 years" 
label var score_2018 "Score 2018"
label var score_mean "Mean Score"
label var score_volatility "St Dev Score"

label var four_yr_delinquency "Delinq. 4 years" 
label var six_yr_delinquency "Delinq. 6 years" 
label var delinquency_2018 "Delinq. 2018" 

label var four_yr_default "Default 4 years" 
label var six_yr_default "Default 6 years" 
label var default_2018 "Default 2018" 

* label var four_yr_percent "Frac Debt Delinq. 4 years"
label var four_yr_percent_c "Frac Debt Delinq. 4 years"
label var six_yr_percent_c "Frac Debt Delinq. 6 years"
label var six_yr_percent_c "Frac Debt Delinq. 6 years"
label var percent_2017_c "Frac Debt Delinq. 2017"

* Cluster variable
cap drop cluster_college
encode(college_code_branch), g(cluster_college)
egen college_fixed_effect = group(college_code_branch)

* Table parameters: IV
local fe "entry_year college_fixed_effect"
local cluster_var "college_code_branch"


	
* Table red. form on tuition and pre-determined outcomes (note that here we use entry year fixed effects only except for age)
local x=0
foreach var in tuition_bill age {
	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4, cl(`cluster_var') a(`fe') // grades 2,3, and 4
	
	g coef_year = .
	g std_err_year = .
	g var_year = .
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		* Figure (within variable loop):
		local position = `y'-1
		replace var_year=`y' in `position'
		replace coef_year=`r(beta)' in `position'
		replace std_err_year=`r(se)' in `position'
	}
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	
	* test equality of coefficients:
	qui test (grade_change_2=grade_change_3= grade_change_4)
	local p_`x' = string(r(p), "%10.2fc")	
	
	
	* graph:
	cap drop LB
	cap drop UB
	g LB = coef_year-1.96*std_err_year
	g UB = coef_year+1.96*std_err_year
	
	twoway (bar coef_year var_year, color(black) sort barwidth(0.8)) (rcap UB LB var_year, lc(black)), ///
		ylabel(,format(%12.4fc) labs(small)) ///
		xlabel(2(1)4, labs(small)) ///
		ytitle(`label_`x'', size(small))  ///
		xtitle("Year of tutition shock after entry", size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/`var'_`size_of_shock'.pdf", replace as(pdf)
	drop coef_year std_err_year var_year
	
	local x=`x'+1
	}
		

* second var: income
local x=2	
qui reghdfe median_hhld_income grade_change_2 grade_change_3 grade_change_4 , cl(cluster_college) a(college_fixed_effect entry_year) // grades 2,3, and 4 
	
	g coef_year = .
	g std_err_year = .
	g var_year = .
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		* Figure (within variable loop):
		local position = `y'-1
		replace var_year=`y' in `position'
		replace coef_year=`r(beta)' in `position'

		replace std_err_year=`r(se)' in `position'
	}
	

	
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su median_hhld_income, d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	label var median_hhld_income "Median income"
	local label_`x' : variable label median_hhld_income
	
	* test equality of coefficients:
	qui test (grade_change_2=grade_change_3= grade_change_4)
	local p_`x' = string(r(p), "%10.2fc")	
	
	* graph:
	cap drop LB
	cap drop UB
	g LB = coef_year-1.96*std_err_year
	g UB = coef_year+1.96*std_err_year
	
	twoway (bar coef_year var_year, color(black) sort barwidth(0.8)) (rcap UB LB var_year, lc(black)), ///
		ylabel(,format(%12.4fc) labs(small)) ///
		xlabel(, labs(small)) ///
		ytitle(`label_`x'', size(small))  ///
		xtitle("Year of tutition shock after entry", size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/income_`size_of_shock'.pdf", replace as(pdf)
	drop coef_year std_err_year var_year
	
	
	local x=`x'+1

* Other variables: no school-level fixed effect
label var first_enrollment_selective_v2 "Selective"
foreach var in public_school  first_enrollment_selective_v2 {
	qui reghdfe `var' grade_change_2 grade_change_3 grade_change_4, cl(cluster_college) a(entry_year) // grades 2,3, and 4 
	
	g coef_year = .
	g std_err_year = .
	g var_year = .
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		* Figure (within variable loop):
		local position = `y'-1
		replace var_year=`y' in `position'
		replace coef_year=`r(beta)' in `position'
		replace std_err_year=`r(se)' in `position'
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	
	* test equality of coefficients: /* Decide on the F-test */
	qui test (grade_change_2=grade_change_3= grade_change_4)
	local p_`x' = string(r(p), "%10.2fc")
	
	* graph:
	cap drop LB
	cap drop UB
	g LB = coef_year-1.96*std_err_year
	g UB = coef_year+1.96*std_err_year
	
	twoway (bar coef_year var_year, color(black) sort barwidth(0.8)) (rcap UB LB var_year, lc(black)), ///
		ylabel(,format(%12.4fc) labs(small)) ///
		xlabel(2(1)4, labs(small)) ///
		ytitle(`label_`x'', size(small))  ///
		xtitle("Year of tutition shock after entry", size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/`var'_`size_of_shock'.pdf", replace as(pdf)
	drop coef_year std_err_year var_year
		
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/first_stage_`size_of_shock'.tex"
	file open fh using "$dir/Tables/first_stage_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} && \multicolumn{1}{c}{(5)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} \cline{10-10}" _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} && \multicolumn{1}{c}{\emph{`label_4'}} \\" _n ///
		"\cline{2-10} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  && `b`z'_4' \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3' && `se`z'_4' \\ \\"  _n 
		}
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' && `obs_4'  \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' && `r2_4' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' && `clusters_4' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' && `mean_4' \\ " _n ///
		"p-value & `p_0' && `p_1' && `p_2' && `p_3' && `p_4' \\ " _n ///
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

* Table: reduced form and IV outcomes
local reg_vars_1 "balance_year4 gradschool_g_by35 bach_g_by35 transfer"	
local reg_vars_2 "four_yr_score six_yr_score score_2018 score_mean score_volatility"
local reg_vars_3 "four_yr_delinquency four_yr_default six_yr_delinquency six_yr_default"
local reg_vars_4 "eight_yr_delinquency eight_yr_default delinquency_2018 default_2018 percent_2017_c"	

local reg_vars_5 "sl_holder_by8years sl_holder_by6years sl_holder_by4years sl_holder_by30"
local reg_vars_6 "sl_bal_at8years sl_bal_at6years sl_bal_at4years sl_bal_at30"
local reg_vars_7 "sl_dq_by8years sl_dq_by6years sl_dq_by4years sl_dq_by30"

local reg_vars_8 "mort2_by8years mort2_by6years mort2_by4years mort2_by30"
local reg_vars_9 "mort2_bal_at8years mort2_bal_at6years mort2_bal_at4years mort2_bal_at30"
local reg_vars_10 "mort2_dq_by8years mort2_dq_by6years mort2_dq_by4years mort2_dq_by30"

local reg_vars_11 "credit_by8years credit_by6years credit_by4years credit_by30"
local reg_vars_12 "credit_card_bal_at8years credit_card_bal_at6years credit_card_bal_at4years credit_card_bal_at30"
local reg_vars_13 "credit_card_dq_by8years credit_card_dq_by6years credit_card_dq_by4years credit_card_dq_by30"

local reg_vars_14 "auto_by8years auto_by6years auto_by4years auto_by30"
local reg_vars_15 "auto_bal_at8years auto_bal_at6years auto_bal_at4years auto_bal_at30"
local reg_vars_16 "auto_dq_by8years auto_dq_by6years auto_dq_by4years auto_dq_by30"

local reg_vars_17 "mean_agi_at30 diff_agi_30_initial mean_agi_at30 diff_agi_30_initial"

* THIS IS A CRUCIAL PARAMETER!!!!! NUMBER OF TABLES
local numtables = 17

*****************************
* 1) Figures:
forvalues tablenum=1/`numtables' { // 4 vars in each table
	local x=0
	foreach var in `reg_vars_`tablenum'' {
		qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4, cl(cluster_college) a(college_fixed_effect entry_year) // grades 2,3, and 4
		
		g coef_year = .
		g std_err_year = .
		g var_year = .
			
		forvalues y=2/4 {
			store_regular4 grade_change_`y'
			local b`y'_`x' = "$`r(beta)'`r(star)'$"
			local se`y'_`x' = "`r(se)'"
			
			* Figure (within variable loop):
			local position = `y'-1
			replace var_year=`y' in `position'
			replace coef_year=`r(beta)' in `position'
			replace std_err_year=`r(se)' in `position'
		}
			
		local obs_`x'= string(e(N), "%10.0fc")
		local r2_`x'= string(e(r2), "%10.2fc")
		local clusters_`x'= string(e(N_clust), "%10.0fc")

		qui su `var', d
		local mean_`x' = string(r(mean), "%12.4fc")
		
		* construct tables:
		local label_`x' : variable label `var' 
		
		* graph:
		cap drop LB
		cap drop UB
		g LB = coef_year-1.96*std_err_year
		g UB = coef_year+1.96*std_err_year
		
		twoway (bar coef_year var_year, color(black) sort barwidth(0.8)) (rcap UB LB var_year, lc(black)), ///
			ylabel(,format(%12.4fc) labs(small)) ///
			xlabel(2(1)4, labs(small)) ///
			ytitle(`label_`x'', size(small))  ///
			xtitle("Year of tutition shock after entry", size(small)) ///
			graphregion(color(white)) bgcolor(white) legend(off)
			
			graph export "$dir/Figures/`var'_`size_of_shock'.pdf", replace as(pdf)
		drop coef_year std_err_year var_year
		
		local x=`x'+1
		}

	* 2) output tables:	

		cap file close fh
		capture erase "$dir/Tables/red_form_`size_of_shock'_`tablenum'.tex"
		file open fh using "$dir/Tables/red_form_`size_of_shock'_`tablenum'.tex", write replace

		file write fh ///
			"\begin{tabular}{l ccccccc}" _n ///
			"\toprule" _n ///
			" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
			"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
			" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
			"\cline{2-8} " _n
			
			
							
			forvalues z=2/4 {
			file write fh "Year `z' &  `b`z'_0' && `b`z'_1' && `b`z'_2' && `b`z'_3'  \\ "  _n ///
				"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
			}
				
							
			file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'  \\ " _n ///
			"R-squared & `r2_0' && `r2_1' && `r2_2'  && `r2_3'  \\ " _n  ///
			"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
			"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
			
			
		file write fh ///
			"\bottomrule" _n ///
			"\end{tabular}"  _n _n _n _n _n

		file close fh


	
*******************************************************************
* IV Tables:
	local n_vars : word count `reg_vars_`tablenum'' 
	di `n_vars'
	local c_columns = `n_vars'-1
	local table_declaration "l c"
	local table_clines ""
	local number_header " & "
	local var_header " & "

	local x=0
	
	local b = "\emph{Tuition yrs. 1-4} "
	local se = " "
	local obs = " Observations "
	local r2 = " R-squared "
	local clusters = " Clusters "
	local mean = " Mean "
	
	foreach var in `reg_vars_`tablenum''  {

		qui ivreghdfe `var' (tuition_bill = grade_change_2 grade_change_3 grade_change_4 ) ///
			,   cl(cluster_college) a(college_fixed_effect entry_year) // grades 2,3, and 4 instrument debt
			
		* construct tables:
		local label : variable label `var' 

		* reg coefs:
		store_regular4 tuition_bill
	
		local y = `x'+1

		if `x'>0 {
			if `x'<`n_vars' {
				local table_declaration = "`table_declaration'"+"cc"
			}
			local number_header = "`number_header'" + " && " + "\multicolumn{1}{c}{(`y')}"
			local var_header = "`var_header'" + " && " + "\multicolumn{1}{c}{\emph{`label'}}"
			local b = "`b'" + " && " + "$`r(beta)'`r(star)'$"
			local se = "`se'" + " && " + "`r(se)'"
			local obs = "`obs'" + " && " + string(e(N), "%10.0fc")
			local r2 = "`r2'" + " && " + string(e(r2), "%10.2fc")
			local clusters = "`clusters'" + " && " + string(e(N_clust), "%10.0fc")
			qui su `var', d
			local mean = "`mean'" + " && " + string(r(mean), "%12.4fc")
	
		}
		if `x'==0 {
			local number_header = "`number_header'"  + " \multicolumn{1}{c}{(`y')}"
			local var_header = "`var_header'" + " \multicolumn{1}{c}{\emph{`label'}}"
			local b = "`b'" + "& " + "$`r(beta)'`r(star)'$"
			local se = "`se'" + "& " + "`r(se)'"
			local obs = "`obs'" + "& " + string(e(N), "%10.0fc")
			local r2 = "`r2'" + "& " + string(e(r2), "%10.2fc")
			local clusters = "`clusters'" + "& " + string(e(N_clust), "%10.0fc")
			qui su `var', d
			local mean = "`mean'" + "& " + string(r(mean), "%12.4fc")
		}

		local aux = 2*`y'
		local table_clines = "`table_clines'" + " \cline{`aux'-`aux'}"
		local x=`x'+1
	}
		local table_full_line = "\cline{2-`aux'} "

	cap file close fh
		capture erase "$dir/Tables/IV_`size_of_shock'_`tablenum'.tex"
		file open fh using "$dir/Tables/IV_`size_of_shock'_`tablenum'.tex", write replace

		file write fh ///
			"\begin{tabular}{`table_declaration'}" _n ///
			"\toprule" _n 
			
		file write fh "`number_header' \\" _n ///
			"`table_clines' " _n ///
			"`var_header' \\" _n ///	
			"`table_full_line' " _n
			
		file write fh ///
			"`b' \\ "  _n ///
			"`se'  \\ \\"  _n ///
			"`obs'  \\ " _n ///
			"`clusters'  \\ " _n ///
			"`mean'  \\ " _n
			
			
		file write fh ///
			"\bottomrule" _n ///
			"\end{tabular}"  _n _n _n _n _n

	file close fh

	} // tablenum

********************************************************************	


* HETEROG 1: effect of tuition change on main outcomes by school selectivity

forvalues tablenum=1/1 { // 4 vars in each table	
		
	local x=0
	foreach var in `reg_vars_`tablenum'' {
	
	cap drop selective_grade_*
	g selective_grade_2 = first_enrollment_selective_v2* grade_change_2
	g selective_grade_3 = first_enrollment_selective_v2* grade_change_3
	g selective_grade_4 = first_enrollment_selective_v2* grade_change_4


	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4  ///
		selective_grade_2 selective_grade_3 selective_grade_4, cl(cluster_college) a(college_fixed_effect entry_year) // grades 2,3, and 4
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		store_regular4 selective_grade_`y'
		local v`y'_`x' = "$`r(beta)'`r(star)'$"
		local v_se`y'_`x' = "`r(se)'"
	
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/selectivity_`size_of_shock'.tex"
	file open fh using "$dir/Tables/selectivity_`size_of_shock'.tex", write replace


	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)}  \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
		}
		
		forvalues z=2/4 {
			file write fh "Year `z' x Selective &  `v`z'_0' && `v`z'_1' &&  `v`z'_2' && `v`z'_3'  \\ "  _n ///
		"& `v_se`z'_0' && `v_se`z'_1' && `v_se`z'_2' && `v_se`z'_3' \\ \\"  _n 	
		}
			
			
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

	
* IV heterog:
cap drop tuition_het
g tuition_het = tuition_bill * first_enrollment_selective_v2
local x=0


foreach var in `reg_vars_`tablenum'' {

	qui ivreghdfe `var' (tuition_bill tuition_het = grade_change_2 grade_change_3 grade_change_4  ///
		selective_grade_2 selective_grade_3 selective_grade_4 ) ///
		, cl(cluster_college) a(entry_year college_fixed_effect)  // grades 2,3, and 4 instrument debt
		
	store_regular4 tuition_bill
	local b_`x' = "$`r(beta)'`r(star)'$"
	local se_`x' = "`r(se)'"
	
	store_regular4 tuition_het
	local b2_`x' = "$`r(beta)'`r(star)'$"
	local se2_`x' = "`r(se)'"
 		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/IV_selective_`size_of_shock'.tex"
	file open fh using "$dir/Tables/IV_selective_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}}  && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		file write fh "Tuition years 1-4 &  `b_0' && `b_1' &&  `b_2' && `b_3' \\ "  _n ///
			"& `se_0' && `se_1' && `se_2' && `se_3'  \\ \\"  _n 
	
		file write fh "Tuition x Selective &  `b2_0' && `b2_1' &&  `b2_2' && `b2_3' \\ "  _n ///
			"& `se2_0' && `se2_1' && `se2_2' && `se2_3'  \\ \\"  _n 
	
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'   \\ " _n ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

	}

* HETEROG 2: effect of tuition change on main outcomes by zip code income

forvalues tablenum=1/1 { // 4 vars in each table	
	qui su median_hhld_income, d
	g low_income = median_hhld_income<r(p25)
	
	local x=0
	foreach var in `reg_vars_`tablenum'' {
	
	cap drop low_income_grade_*
	g low_income_grade_2 = low_income* grade_change_2
	g low_income_grade_3 = low_income* grade_change_3
	g low_income_grade_4 = low_income* grade_change_4


	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4  ///
		low_income_grade_2 low_income_grade_3 low_income_grade_4, cl(cluster_college) a(low_income college_fixed_effect entry_year) // grades 2,3, and 4
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		store_regular4 low_income_grade_`y'
		local v`y'_`x' = "$`r(beta)'`r(star)'$"
		local v_se`y'_`x' = "`r(se)'"
	
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/income_`size_of_shock'.tex"
	file open fh using "$dir/Tables/income_`size_of_shock'.tex", write replace


	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)}  \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
		}
		
		forvalues z=2/4 {
			file write fh "Year `z' x Low Income &  `v`z'_0' && `v`z'_1' &&  `v`z'_2' && `v`z'_3'  \\ "  _n ///
		"& `v_se`z'_0' && `v_se`z'_1' && `v_se`z'_2' && `v_se`z'_3' \\ \\"  _n 	
		}
			
			
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

	
* IV heterog:
cap drop tuition_het
g tuition_het = tuition_bill * low_income
local x=0


foreach var in `reg_vars_`tablenum'' {

	qui ivreghdfe `var' (tuition_bill tuition_het = grade_change_2 grade_change_3 grade_change_4  ///
		low_income_grade_2 low_income_grade_3 low_income_grade_4) ///
		, cl(cluster_college) a(entry_year college_fixed_effect low_income)  // grades 2,3, and 4 instrument debt
		
	store_regular4 tuition_bill
	local b_`x' = "$`r(beta)'`r(star)'$"
	local se_`x' = "`r(se)'"
	
	store_regular4 tuition_het
	local b2_`x' = "$`r(beta)'`r(star)'$"
	local se2_`x' = "`r(se)'"
 		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/IV_income_`size_of_shock'.tex"
	file open fh using "$dir/Tables/IV_income_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}}  && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		file write fh "Tuition years 1-4 &  `b_0' && `b_1' &&  `b_2' && `b_3' \\ "  _n ///
			"& `se_0' && `se_1' && `se_2' && `se_3'  \\ \\"  _n 
	
		file write fh "Tuition x Low Income &  `b2_0' && `b2_1' &&  `b2_2' && `b2_3' \\ "  _n ///
			"& `se2_0' && `se2_1' && `se2_2' && `se2_3'  \\ \\"  _n 
	
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'   \\ " _n ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

	}	


* HETEROG 3: post limit increase in 2007

forvalues tablenum=1/1 { // 4 vars in each table	
	cap drop post_credit
	g post_credit = yearchange>2007 if yearchange>0 // !!!!
	
	local x=0
	foreach var in `reg_vars_`tablenum'' {
	
	cap drop post_credit_grade_*
	g post_credit_grade_2 = post_credit* grade_change_2
	g post_credit_grade_3 = post_credit* grade_change_3
	g post_credit_grade_4 = post_credit* grade_change_4


	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4  ///
		post_credit_grade_2 post_credit_grade_3 post_credit_grade_4, cl(cluster_college) a(post_credit college_fixed_effect entry_year) // grades 2,3, and 4
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		store_regular4 post_credit_grade_`y'
		local v`y'_`x' = "$`r(beta)'`r(star)'$"
		local v_se`y'_`x' = "`r(se)'"
	
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/post_credit_`size_of_shock'.tex"
	file open fh using "$dir/Tables/post_credit_`size_of_shock'.tex", write replace


	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)}  \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
		}
		
		forvalues z=2/4 {
			file write fh "Year `z' x Post 2007 &  `v`z'_0' && `v`z'_1' &&  `v`z'_2' && `v`z'_3'  \\ "  _n ///
		"& `v_se`z'_0' && `v_se`z'_1' && `v_se`z'_2' && `v_se`z'_3' \\ \\"  _n 	
		}
			
			
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

	
* IV heterog post 2007:
cap drop tuition_het
g tuition_het = tuition_bill * post_credit
local x=0


foreach var in `reg_vars_`tablenum'' {

	qui ivreghdfe `var' (tuition_bill tuition_het = grade_change_2 grade_change_3 grade_change_4  ///
		post_credit_grade_2 post_credit_grade_3 post_credit_grade_4) ///
		, cl(cluster_college) a(entry_year college_fixed_effect post_credit)  // grades 2,3, and 4 instrument debt
		
	store_regular4 tuition_bill
	local b_`x' = "$`r(beta)'`r(star)'$"
	local se_`x' = "`r(se)'"
	
	store_regular4 tuition_het
	local b2_`x' = "$`r(beta)'`r(star)'$"
	local se2_`x' = "`r(se)'"
 		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/IV_postcredit_`size_of_shock'.tex"
	file open fh using "$dir/Tables/IV_postcredit_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}}  && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		file write fh "Tuition years 1-4 &  `b_0' && `b_1' &&  `b_2' && `b_3' \\ "  _n ///
			"& `se_0' && `se_1' && `se_2' && `se_3'  \\ \\"  _n 
	
		file write fh "Tuition x Limit increase &  `b2_0' && `b2_1' &&  `b2_2' && `b2_3' \\ "  _n ///
			"& `se2_0' && `se2_1' && `se2_2' && `se2_3'  \\ \\"  _n 
	
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'   \\ " _n ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

	}	

	
* HETEROG 3b: post limit increase in 2007
* Consider cohorts that first enrolled before 2003 (1998 - 2002)

forvalues tablenum=1/1 { // 4 vars in each table	
	cap drop post_credit
	g post_credit = entry_year<=2002
	
	local x=0
	foreach var in `reg_vars_`tablenum'' {
	
	cap drop post_credit_grade_*
	g post_credit_grade_2 = post_credit* grade_change_2
	g post_credit_grade_3 = post_credit* grade_change_3
	g post_credit_grade_4 = post_credit* grade_change_4


	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4  ///
		post_credit_grade_2 post_credit_grade_3 post_credit_grade_4, cl(cluster_college) a(post_credit college_fixed_effect entry_year) // grades 2,3, and 4
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		store_regular4 post_credit_grade_`y'
		local v`y'_`x' = "$`r(beta)'`r(star)'$"
		local v_se`y'_`x' = "`r(se)'"
	
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/post_credit_v2_`size_of_shock'.tex"
	file open fh using "$dir/Tables/post_credit_v2_`size_of_shock'.tex", write replace


	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)}  \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
		}
		
		forvalues z=2/4 {
			file write fh "Year `z' x Post 2007 &  `v`z'_0' && `v`z'_1' &&  `v`z'_2' && `v`z'_3'  \\ "  _n ///
		"& `v_se`z'_0' && `v_se`z'_1' && `v_se`z'_2' && `v_se`z'_3' \\ \\"  _n 	
		}
			
			
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

	
* IV heterog post 2007:
cap drop tuition_het
g tuition_het = tuition_bill * post_credit
local x=0


foreach var in `reg_vars_`tablenum'' {

	qui ivreghdfe `var' (tuition_bill tuition_het = grade_change_2 grade_change_3 grade_change_4  ///
		post_credit_grade_2 post_credit_grade_3 post_credit_grade_4) ///
		, cl(cluster_college) a(entry_year college_fixed_effect post_credit)  // grades 2,3, and 4 instrument debt
		
	store_regular4 tuition_bill
	local b_`x' = "$`r(beta)'`r(star)'$"
	local se_`x' = "`r(se)'"
	
	store_regular4 tuition_het
	local b2_`x' = "$`r(beta)'`r(star)'$"
	local se2_`x' = "`r(se)'"
 		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/IV_postcredit_v2_`size_of_shock'.tex"
	file open fh using "$dir/Tables/IV_postcredit_v2_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}}  && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		file write fh "Tuition years 1-4 &  `b_0' && `b_1' &&  `b_2' && `b_3' \\ "  _n ///
			"& `se_0' && `se_1' && `se_2' && `se_3'  \\ \\"  _n 
	
		file write fh "Tuition x Limit increase &  `b2_0' && `b2_1' &&  `b2_2' && `b2_3' \\ "  _n ///
			"& `se2_0' && `se2_1' && `se2_2' && `se2_3'  \\ \\"  _n 
	
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'   \\ " _n ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

	}	

	

* HETEROG 4: financial education

g financial_educ = yearchange>=year_fin_educ+5 if yearchange<. // students at least in year 5 after enrollment
encode college_state, g(state_aux) label(state_lab)
egen cohort_state_fe = group(entry_year state_aux)

forvalues tablenum=1/1 { // 4 vars in each table	
	
	local x=0
	foreach var in `reg_vars_`tablenum'' {
	
	cap drop financial_educ_grade_*
	g financial_educ_grade_2 = financial_educ* grade_change_2
	g financial_educ_grade_3 = financial_educ* grade_change_3
	g financial_educ_grade_4 = financial_educ* grade_change_4


	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4  ///
		financial_educ_grade_2 financial_educ_grade_3 financial_educ_grade_4, cl(cluster_college) a(financial_educ college_fixed_effect cohort_state_fe) // grades 2,3, and 4
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		store_regular4 financial_educ_grade_`y'
		local v`y'_`x' = "$`r(beta)'`r(star)'$"
		local v_se`y'_`x' = "`r(se)'"
	
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/financial_educ_`size_of_shock'.tex"
	file open fh using "$dir/Tables/financial_educ_`size_of_shock'.tex", write replace


	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)}  \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
		}
		
		forvalues z=2/4 {
			file write fh "Year `z' x Financial Education &  `v`z'_0' && `v`z'_1' &&  `v`z'_2' && `v`z'_3'  \\ "  _n ///
		"& `v_se`z'_0' && `v_se`z'_1' && `v_se`z'_2' && `v_se`z'_3' \\ \\"  _n 	
		}
			
			
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh
	
* IV heterog fin educ:
cap drop tuition_het
g tuition_het = financial_educ * tuition_bill
local x=0


foreach var in `reg_vars_`tablenum'' {

	qui ivreghdfe `var' (tuition_bill tuition_het = grade_change_2 grade_change_3 grade_change_4  ///
		financial_educ_grade_2 financial_educ_grade_3 financial_educ_grade_4) ///
		, cl(cluster_college) a(entry_year college_fixed_effect financial_educ)  // grades 2,3, and 4 instrument debt
		
	store_regular4 tuition_bill
	local b_`x' = "$`r(beta)'`r(star)'$"
	local se_`x' = "`r(se)'"
	
	store_regular4 tuition_het
	local b2_`x' = "$`r(beta)'`r(star)'$"
	local se2_`x' = "`r(se)'"
 		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/IV_financial_educ_`size_of_shock'.tex"
	file open fh using "$dir/Tables/IV_financial_educ_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}}  && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		file write fh "Tuition years 1-4 &  `b_0' && `b_1' &&  `b_2' && `b_3' \\ "  _n ///
			"& `se_0' && `se_1' && `se_2' && `se_3'  \\ \\"  _n 
	
		file write fh "Tuition x Financial Education &  `b2_0' && `b2_1' &&  `b2_2' && `b2_3' \\ "  _n ///
			"& `se2_0' && `se2_1' && `se2_2' && `se2_3'  \\ \\"  _n 
	
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'   \\ " _n ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

	}	


* HETEROG 5: public schools
g public = public_school
forvalues tablenum=1/1 { // 4 vars in each table	
	
	local x=0
	foreach var in `reg_vars_`tablenum'' {
	
	cap drop public_grade_*
	g public_grade_2 = public* grade_change_2
	g public_grade_3 = public* grade_change_3
	g public_grade_4 = public* grade_change_4


	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4  ///
		public_grade_2 public_grade_3 public_grade_4, cl(cluster_college) a( college_fixed_effect entry_year) // grades 2,3, and 4
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		store_regular4 public_grade_`y'
		local v`y'_`x' = "$`r(beta)'`r(star)'$"
		local v_se`y'_`x' = "`r(se)'"
	
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/public_`size_of_shock'.tex"
	file open fh using "$dir/Tables/public_`size_of_shock'.tex", write replace


	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)}  \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
		}
		
		forvalues z=2/4 {
			file write fh "Year `z' x Public School &  `v`z'_0' && `v`z'_1' &&  `v`z'_2' && `v`z'_3'  \\ "  _n ///
		"& `v_se`z'_0' && `v_se`z'_1' && `v_se`z'_2' && `v_se`z'_3' \\ \\"  _n 	
		}
			
			
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh
	
* IV heterog fin educ:
cap drop tuition_het
g tuition_het = public * tuition_bill
local x=0


foreach var in `reg_vars_`tablenum'' {

	qui ivreghdfe `var' (tuition_bill tuition_het = grade_change_2 grade_change_3 grade_change_4  ///
		public_grade_2 public_grade_3 public_grade_4) ///
		, cl(cluster_college) a(entry_year college_fixed_effect )  // grades 2,3, and 4 instrument debt
		
	store_regular4 tuition_bill
	local b_`x' = "$`r(beta)'`r(star)'$"
	local se_`x' = "`r(se)'"
	
	store_regular4 tuition_het
	local b2_`x' = "$`r(beta)'`r(star)'$"
	local se2_`x' = "`r(se)'"
 		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/IV_public_`size_of_shock'.tex"
	file open fh using "$dir/Tables/IV_public_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}}  && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		file write fh "Tuition years 1-4 &  `b_0' && `b_1' &&  `b_2' && `b_3' \\ "  _n ///
			"& `se_0' && `se_1' && `se_2' && `se_3'  \\ \\"  _n 
	
		file write fh "Tuition x Public School &  `b2_0' && `b2_1' &&  `b2_2' && `b2_3' \\ "  _n ///
			"& `se2_0' && `se2_1' && `se2_2' && `se2_3'  \\ \\"  _n 
	
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'   \\ " _n ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

}

* HETEROG 6: has a baseline credit score
forvalues tablenum=1/1 { // 4 vars in each table	
	
	local x=0
	foreach var in `reg_vars_`tablenum'' {
	
	cap drop has_score_grade_*
	g has_score_grade_2 = has_score* grade_change_2
	g has_score_grade_3 = has_score* grade_change_3
	g has_score_grade_4 = has_score* grade_change_4


	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4  ///
		has_score_grade_2 has_score_grade_3 has_score_grade_4, cl(cluster_college) a(has_score college_fixed_effect entry_year) // grades 2,3, and 4
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		store_regular4 has_score_grade_`y'
		local v`y'_`x' = "$`r(beta)'`r(star)'$"
		local v_se`y'_`x' = "`r(se)'"
	
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/has_score_`size_of_shock'.tex"
	file open fh using "$dir/Tables/has_score_`size_of_shock'.tex", write replace


	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)}  \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
		}
		
		forvalues z=2/4 {
			file write fh "Year `z' x Has Score &  `v`z'_0' && `v`z'_1' &&  `v`z'_2' && `v`z'_3'  \\ "  _n ///
		"& `v_se`z'_0' && `v_se`z'_1' && `v_se`z'_2' && `v_se`z'_3' \\ \\"  _n 	
		}
			
			
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh
 
* IV heterog has a score:
cap drop tuition_het
g tuition_het = has_score * tuition_bill
local x=0


foreach var in `reg_vars_`tablenum'' {

	qui ivreghdfe `var' (tuition_bill tuition_het = grade_change_2 grade_change_3 grade_change_4  ///
		has_score_grade_2 has_score_grade_3 has_score_grade_4) ///
		, cl(cluster_college) a(entry_year has_score college_fixed_effect )  // grades 2,3, and 4 instrument debt
		
	store_regular4 tuition_bill
	local b_`x' = "$`r(beta)'`r(star)'$"
	local se_`x' = "`r(se)'"
	
	store_regular4 tuition_het
	local b2_`x' = "$`r(beta)'`r(star)'$"
	local se2_`x' = "`r(se)'"
 		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/IV_has_score_`size_of_shock'.tex"
	file open fh using "$dir/Tables/IV_has_score_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}}  && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		file write fh "Tuition years 1-4 &  `b_0' && `b_1' &&  `b_2' && `b_3' \\ "  _n ///
			"& `se_0' && `se_1' && `se_2' && `se_3'  \\ \\"  _n 
	
		file write fh "Tuition x Has Score &  `b2_0' && `b2_1' &&  `b2_2' && `b2_3' \\ "  _n ///
			"& `se2_0' && `se2_1' && `se2_2' && `se2_3'  \\ \\"  _n 
	
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'   \\ " _n ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh

}	

* HETEROG 7: Score below median (w/out zeros)

cap drop low_score
qui su baseline_score, d
g low_score = baseline_score<r(p50) if mi(baseline_score)==0

forvalues tablenum=1/1 { // 4 vars in each table	
	
	local x=0
	foreach var in `reg_vars_`tablenum'' {
	
	cap drop low_score_grade_*
	g low_score_grade_2 = low_score* grade_change_2
	g low_score_grade_3 = low_score* grade_change_3
	g low_score_grade_4 = low_score* grade_change_4


	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4  ///
		low_score_grade_2 low_score_grade_3 low_score_grade_4, cl(cluster_college) a(low_score college_fixed_effect entry_year) // grades 2,3, and 4
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		store_regular4 low_score_grade_`y'
		local v`y'_`x' = "$`r(beta)'`r(star)'$"
		local v_se`y'_`x' = "`r(se)'"
	
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/low_score_`size_of_shock'.tex"
	file open fh using "$dir/Tables/low_score_`size_of_shock'.tex", write replace


	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)}  \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
		}
		
		forvalues z=2/4 {
			file write fh "Year `z' x Low Score &  `v`z'_0' && `v`z'_1' &&  `v`z'_2' && `v`z'_3'  \\ "  _n ///
		"& `v_se`z'_0' && `v_se`z'_1' && `v_se`z'_2' && `v_se`z'_3' \\ \\"  _n 	
		}
			
			
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh
	
* IV heterog low score:
cap drop tuition_het
g tuition_het = low_score * tuition_bill
local x=0


foreach var in `reg_vars_`tablenum'' {

	qui ivreghdfe `var' (tuition_bill tuition_het = grade_change_2 grade_change_3 grade_change_4  ///
		low_score_grade_2 low_score_grade_3 low_score_grade_4) ///
		, cl(cluster_college) a(entry_year low_score college_fixed_effect )  // grades 2,3, and 4 instrument debt
		
	store_regular4 tuition_bill
	local b_`x' = "$`r(beta)'`r(star)'$"
	local se_`x' = "`r(se)'"
	
	store_regular4 tuition_het
	local b2_`x' = "$`r(beta)'`r(star)'$"
	local se2_`x' = "`r(se)'"
 		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/IV_low_score_`size_of_shock'.tex"
	file open fh using "$dir/Tables/IV_low_score_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}}  && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		file write fh "Tuition years 1-4 &  `b_0' && `b_1' &&  `b_2' && `b_3' \\ "  _n ///
			"& `se_0' && `se_1' && `se_2' && `se_3'  \\ \\"  _n 
	
		file write fh "Tuition x Low Score &  `b2_0' && `b2_1' &&  `b2_2' && `b2_3' \\ "  _n ///
			"& `se2_0' && `se2_1' && `se2_2' && `se2_3'  \\ \\"  _n 
	
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'   \\ " _n ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh
	
	}


* HETEROG 8: Score below median (with zeros)

cap drop low_score
qui su baseline_score, d
g low_score = baseline_score<r(p50) // zeros are also low

forvalues tablenum=1/1 { // 4 vars in each table	
	
	local x=0
	foreach var in `reg_vars_`tablenum'' {
	
	cap drop low_score_grade_*
	g low_score_grade_2 = low_score* grade_change_2
	g low_score_grade_3 = low_score* grade_change_3
	g low_score_grade_4 = low_score* grade_change_4


	qui reghdfe `var'  grade_change_2 grade_change_3 grade_change_4  ///
		low_score_grade_2 low_score_grade_3 low_score_grade_4, cl(cluster_college) a(low_score college_fixed_effect entry_year) // grades 2,3, and 4
		
	forvalues y=2/4 {
		store_regular4 grade_change_`y'
		local b`y'_`x' = "$`r(beta)'`r(star)'$"
		local se`y'_`x' = "`r(se)'"
		
		store_regular4 low_score_grade_`y'
		local v`y'_`x' = "$`r(beta)'`r(star)'$"
		local v_se`y'_`x' = "`r(se)'"
	
	}
	
		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/low_score_full_`size_of_shock'.tex"
	file open fh using "$dir/Tables/low_score_full_`size_of_shock'.tex", write replace


	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)}  \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}} && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		forvalues z=2/4 {
		file write fh "Year `z' &  `b`z'_0' && `b`z'_1' &&  `b`z'_2' && `b`z'_3'  \\ "  _n ///
			"& `se`z'_0' && `se`z'_1' && `se`z'_2' && `se`z'_3'  \\ \\"  _n 
		}
		
		forvalues z=2/4 {
			file write fh "Year `z' x Low Score &  `v`z'_0' && `v`z'_1' &&  `v`z'_2' && `v`z'_3'  \\ "  _n ///
		"& `v_se`z'_0' && `v_se`z'_1' && `v_se`z'_2' && `v_se`z'_3' \\ \\"  _n 	
		}
			
			
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2'  && `obs_3' \\ " _n ///
		"R-squared & `r2_0' && `r2_1' && `r2_2' && `r2_3' \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3'  \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3'  \\ " _n
		
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh
	
* IV heterog low score:
cap drop tuition_het
g tuition_het = low_score * tuition_bill
local x=0


foreach var in `reg_vars_`tablenum'' {

	qui ivreghdfe `var' (tuition_bill tuition_het = grade_change_2 grade_change_3 grade_change_4  ///
		low_score_grade_2 low_score_grade_3 low_score_grade_4) ///
		, cl(cluster_college) a(entry_year low_score college_fixed_effect )  // grades 2,3, and 4 instrument debt
		
	store_regular4 tuition_bill
	local b_`x' = "$`r(beta)'`r(star)'$"
	local se_`x' = "`r(se)'"
	
	store_regular4 tuition_het
	local b2_`x' = "$`r(beta)'`r(star)'$"
	local se2_`x' = "`r(se)'"
 		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/IV_low_score_full_`size_of_shock'.tex"
	file open fh using "$dir/Tables/IV_low_score_full_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} && \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} \cline{6-6} \cline{8-8} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} && \multicolumn{1}{c}{\emph{`label_2'}}  && \multicolumn{1}{c}{\emph{`label_3'}} \\" _n ///
		"\cline{2-8} " _n
		
						
		file write fh "Tuition years 1-4 &  `b_0' && `b_1' &&  `b_2' && `b_3' \\ "  _n ///
			"& `se_0' && `se_1' && `se_2' && `se_3'  \\ \\"  _n 
	
		file write fh "Tuition x Low Score &  `b2_0' && `b2_1' &&  `b2_2' && `b2_3' \\ "  _n ///
			"& `se2_0' && `se2_1' && `se2_2' && `se2_3'  \\ \\"  _n 
	
			
						
		file write fh "Observations & `obs_0' && `obs_1' && `obs_2' && `obs_3'   \\ " _n ///
		"Clusters & `clusters_0' && `clusters_1' && `clusters_2' && `clusters_3' \\ " _n ///
		"Mean & `mean_0' && `mean_1' && `mean_2' && `mean_3' \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh
	
	}


	
}
/*
* Linear specification:
local x=0
foreach var in `reg_vars_`tablenum'' {

	qui reghdfe `var'  grade_change_linear if (grade_when_change<=4 & grade_when_change>=2), cl(cluster_college) a(cluster_college entry_year) // grades 2,3, and 4
	
	store_regular4 grade_change_linear
	local b_`x' = "$`r(beta)'`r(star)'$"
		local se_`x' = "`r(se)'"

		
	local obs_`x'= string(e(N), "%10.0fc")
	local r2_`x'= string(e(r2), "%10.2fc")
	local clusters_`x'= string(e(N_clust), "%10.0fc")

	qui su `var', d
	local mean_`x' = string(r(mean), "%12.4fc")
	
	* construct tables:
	local label_`x' : variable label `var' 
	
		
	local x=`x'+1
	}

	cap file close fh
	capture erase "$dir/Tables/debt_linear_`size_of_shock'.tex"
	file open fh using "$dir/Tables/debt_linear_`size_of_shock'.tex", write replace

	file write fh ///
		"\begin{tabular}{l ccccccc}" _n ///
		"\toprule" _n ///
		" &  \multicolumn{1}{c}{(1)} && \multicolumn{1}{c}{(2)} &  \multicolumn{1}{c}{(3)} && \multicolumn{1}{c}{(4)} \\ " _n ///
		"\cline{2-2} \cline{4-4} " _n ///
		" & \multicolumn{1}{c}{\emph{`label_0'}} && \multicolumn{1}{c}{\emph{`label_1'}} \\" _n ///
		"\cline{2-4} " _n
		
						
		file write fh "Year &  `b_0' && `b_1' \\ "  _n ///
			"& `se_0' && `se_1' \\ \\"  _n 
			
						
		file write fh "Observations & `obs_0' && `obs_1'  \\ " _n ///
		"R-squared & `r2_0' && `r2_1'  \\ " _n  ///
		"Clusters & `clusters_0' && `clusters_1'  \\ " _n ///
		"Mean & `mean_0' && `mean_1'  \\ " _n
		
		
	file write fh ///
		"\bottomrule" _n ///
		"\end{tabular}"  _n _n _n _n _n

	file close fh
*/	
	
 	
		
}	
	

	

*********************************************************************
************************** Figures: *********************************
*********************************************************************

***************************************************		
* cross state appendix figure and table ***********
***************************************************		
use "$dir/data/working_data.dta", replace

keep if tag_ind==1

encode cid, g(student_id)
encode college_state, g(state_aux) label(state_lab)
drop if state_aux==.
twoway (histogram state_aux, fcolor(gs10) lwidth(medium) lcolor(white) freq ) ///
	, ylabel(,   labs(small)) ///
	xlabel(1(1)50, valuelabel labs(tiny) angle(45)) ///
	ytitle("Number of students", size(small))  ///
	xtitle("", size(small)) ///
	graphregion(color(white)) bgcolor(white) legend(off) ///
	 legend(off)
		
graph export "$dir/Figures/by_state.pdf", replace as(pdf) // does not look great
	
	collapse (count) number = student_id, by(state_aux)
	decode state_aux, g(college_state)
	
	capture erase "$dir/Tables/by_state.tex"
	capture file close fh

	file open fh using "$dir/Tables/by_state.tex", write replace
	

	file write fh ///
		"\begin{tabular}{lc c lc}" _n ///
		"\toprule" _n ///
	" State &   && State &  \\" _newline ///
	"\hline" _newline

	
	forvalues x=1/25 {
	local state = college_state[`x']
	local number = string(number[`x'], "%10.0fc") 
	local state_2 = college_state[`x'+26]
	local number_2 = string(number[`x'+26], "%10.0fc") 
	file write fh "\hspace{5 pt} `state'  & `number' && `state_2'  & `number_2' \\ " _newline
	
	}
	
file write fh %-16s "\hline" _newline %-16s "\end{tabular}"
file close fh

* time-series coverage by entry-year
use "$dir/data/working_data.dta", replace
keep if tag_ind==1

encode cid, g(student_id)
collapse (count) number = student_id, by(entry_year)
	format entry_year %ty
	keep if entry_year>=2000
	twoway (bar number entry_year, yaxis(1) fcolor(gs10) lwidth(medium) lcolor(white)) ///
		, ylabel(0(1000)5000,format(%12.0fc) labs(small)) ///
		xlabel(2000(2)2013, labs(small)) ///
		ytitle("Number of students", size(small))  ///
		xtitle("Entry year to first college", size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/ts_sample.pdf", replace as(pdf)

* time-series of total tuition bill
use "$dir/data/working_data.dta", replace
keep if tag_ind==1
keep if entry_year<=2013 & entry_year>=2000
replace tuition_bill=tuition_bill*10000
collapse tuition_bill, by(entry_year)
	format entry_year %ty
		twoway (bar tuition_bill entry_year, yaxis(1) fcolor(gs10) lwidth(medium) lcolor(white)) ///
		, ylabel(0(10000)60000,format(%12.0fc) labs(small)) ///
		xlabel(2000(2)2013, labs(small)) ///
		ytitle("Tuition first college yrs 1-4", size(small))  ///
		xtitle("Entry year to first college", size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/ts_tuition.pdf", replace as(pdf)	
		


**********************************************************************
* time series of tuition changes by school in sample
use "$dir/data/working_data.dta", replace

* Tuition changes in sample:
foreach size_of_shock in 1000 {
	
preserve
	keep if dummy_change_`size_of_shock'==1

	* keep one shock per school
	cap drop tag
	egen tag = tag(opeid)
	keep if tag==1

	collapse (count) number =  dummy_change_`size_of_shock', by(academicyear)
	format academicyear %ty
	twoway (bar number academicyear, fcolor(gs10) lwidth(medium) lcolor(white)) ///
		, ylabel(0(50)500,format(%12.0fc) labs(small)) ///
		xlabel(2005(2)2013, labs(small)) ///
		ytitle("Number of `size_of_shock' dollar shocks", size(small)) ///
		xtitle(Year, size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/ts_shocks_`size_of_shock'.pdf", replace as(pdf)
restore
* For private and public schools		
preserve
	keep if dummy_change_`size_of_shock'==1

	* keep one shock per school
	cap drop tag
	egen tag = tag(opeid)
	keep if tag==1

	collapse (count) number =  dummy_change_`size_of_shock', by(public_school academicyear)
	format academicyear %ty
	bysort academicyear: egen total = total(number)
	keep if public_school==1
	twoway (bar total academicyear, fcolor(gs10) lwidth(medium) lcolor(white)) ///
			(bar number academicyear, fcolor(black) lwidth(medium) lcolor(white)) ///
		, ylabel(0(50)500,format(%12.0fc) labs(small)) ///
		xlabel(2005(2)2013, labs(small)) ///
		ytitle("Number of `size_of_shock' dollar shocks", size(small)) ///
		xtitle(Year, size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(label(1 Private) label(2 Public))
		
		graph export "$dir/Figures/ts_shocks_`size_of_shock'_public.pdf", replace as(pdf)
		
		
restore

}


**********************************************************************
* time series of human capital outcomes and average student debt
use "$dir/data/working_data.dta", replace
keep if tag_ind==1
keep if entry_year>=2000
collapse balance_year4 gradschool_g_by35 gradschool_g_by25 bach_g_by35 bach_g_by25, by(entry_year)
replace balance_year4=balance_year4*10000
	format entry_year %ty
	twoway (bar balance_year4 entry_year, fcolor(gs10) lwidth(medium) lcolor(white)) ///
		, ylabel(0(4000)20000,format(%12.0fc) labs(small)) ///
		xlabel(2000(2)2013, labs(small)) ///
		ytitle("Average student debt 4 years after entry", size(small)) ///
		xtitle(Year, size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/ts_debt.pdf", replace as(pdf)
		
	twoway (connected bach_g_by25 entry_year, fcolor(gs10) mcolor(black) m(square) lwidth(medium) lcolor(black)) ///
		, ylabel(,format(%12.2fc) labs(small)) ///
		xlabel(2000(2)2013, labs(small)) ///
		ytitle("Fraction with Bachelors at age 25", size(small)) ///
		xtitle(Year, size(small)) ///
		graphregion(color(white)) bgcolor(white) legend(off)
		
		graph export "$dir/Figures/ts_debt.pdf", replace as(pdf)		
		

}



*****************************************************************
************* Appendix: Tuition correlations ********************
*****************************************************************


* Table: OLS relation between tuition and pre-determined outcomes as of 2012
use "$dir/data/working_data.dta", replace

* only one year
keep if academicyear==2012

* one obs per school:
egen tag_school = tag(college_code_branch)
keep if tag_school==1 // 1640 0bservations


* Main outcomes
label var tuition_bill "Tuition yrs 1-4"
label var public_school "Public school"
label var competitive "Competitive"
label var first_enrollment_selective_v2 "Selective"

local reg_vars_1 "public_school first_enrollment_selective_v2"	

* Run up to x where `x' is max number of reg_vars_`x':
forvalues tablenum = 1/1 {
	local n_vars : word count `reg_vars_`tablenum'' 
	di `n_vars'
	local c_columns = `n_vars'-1
	local table_declaration "l c"
	local table_clines ""
	local number_header " & "
	local var_header " & "

	local x=0
	
	local b = "\emph{Tuition yrs. 1-4} "
	local se = " "
	local obs = " Observations "
	local r2 = " R-squared "
	local clusters = " Clusters "
	local mean = " Mean "
	
	foreach var in `reg_vars_`tablenum''  {

		qui reg `var' tuition_bill, robust // no clusters, no fe
		* construct tables:
		local label : variable label `var' 

		* reg coefs:
		store_regular4 tuition
	
		local y = `x'+1

		if `x'>0 {
			if `x'<`n_vars' {
				local table_declaration = "`table_declaration'"+"cc"
			}
			local number_header = "`number_header'" + " && " + "\multicolumn{1}{c}{(`y')}"
			local var_header = "`var_header'" + " && " + "\multicolumn{1}{c}{\emph{`label'}}"
			local b = "`b'" + " && " + "$`r(beta)'`r(star)'$"
			local se = "`se'" + " && " + "`r(se)'"
			local obs = "`obs'" + " && " + string(e(N), "%10.0fc")
			local r2 = "`r2'" + " && " + string(e(r2), "%10.2fc")
			local clusters = "`clusters'" + " && " + string(e(N_clust), "%10.0fc")
			qui su `var', d
			local mean = "`mean'" + " && " + string(r(mean), "%12.4fc")
	
		}
		if `x'==0 {
			local number_header = "`number_header'"  + " \multicolumn{1}{c}{(`y')}"
			local var_header = "`var_header'" + " \multicolumn{1}{c}{\emph{`label'}}"
			local b = "`b'" + "& " + "$`r(beta)'`r(star)'$"
			local se = "`se'" + "& " + "`r(se)'"
			local obs = "`obs'" + "& " + string(e(N), "%10.0fc")
			local r2 = "`r2'" + "& " + string(e(r2), "%10.2fc")
			local clusters = "`clusters'" + "& " + string(e(N_clust), "%10.0fc")
			qui su `var', d
			local mean = "`mean'" + "& " + string(r(mean), "%12.4fc")
		}

		local aux = 2*`y'
		local table_clines = "`table_clines'" + " \cline{`aux'-`aux'}"
		local x=`x'+1
	}
		local table_full_line = "\cline{2-`aux'} "

	cap file close fh
		capture erase "$dir/Tables/school_level_tuition.tex"
		file open fh using "$dir/Tables/school_level_tuition.tex", write replace

		file write fh ///
			"\begin{tabular}{`table_declaration'}" _n ///
			"\toprule" _n 
			
		file write fh "`number_header' \\" _n ///
			"`table_clines' " _n ///
			"`var_header' \\" _n ///	
			"`table_full_line' " _n
			
		file write fh ///
			"`b' \\ "  _n ///
			"`se'  \\ \\"  _n ///
			"`obs'  \\ " _n ///
			"`r2' \\ " _n  ///
			"`clusters'  \\ " _n ///
			"`mean'  \\ " _n
			
			
		file write fh ///
			"\bottomrule" _n ///
			"\end{tabular}"  _n _n _n _n _n

	file close fh

} // tablenum


